package kr.hikt.androidcomplete01.ch06;

import kr.hikt.androidcomplete01.R;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

public class InflationEx3 extends Activity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch06_inflationex2);
		
		Button btn = (Button) findViewById(R.id.btnnewmessage);
		btn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				RelativeLayout rel = (RelativeLayout)View.inflate(InflationEx3.this, R.layout.ch06_newmessage, null);
				
				LinearLayout linear = (LinearLayout)findViewById(R.id.linear);
				if (linear.getChildCount() % 2 == 0) {
					rel.setBackgroundColor(Color.GRAY);
				} else {
					rel.setBackgroundColor(Color.RED);
				}
				linear.addView(rel);
			}
		});
	}
}
